package cn.skyclass.utils
{
	/**
	 * 对日期进行格式化，输出格式化的字符串
	 */
	import mx.formatters.DateFormatter; 
	 
	public class DateFormatter
	{
		public static function format(date:Date, 
			hasDate:Boolean=true, hasTime:Boolean=true, ignoreSecond:Boolean=true):String{
			
			var dStr:String = "0000-00-00";
			var tStr:String = " 00:00";
			var mStr:String = ":00";
			
			if(date != null){
				dStr = date.fullYear + "-" + (date.month+1) + "-" + date.date;
				tStr = " " + date.hours + ":" + date.minutes;
				mStr = ":" + date.seconds;				
			}
			
			var out:String = "";
			out += hasDate ? dStr : "";
			out += hasTime ? tStr : "";
			out += ignoreSecond ? "" : mStr;				
			return out;
		}
		
		public static function format2(date:Date, formatString:String):String{
			var formater:mx.formatters.DateFormatter = new mx.formatters.DateFormatter();
			formater.formatString = formatString;
			return formater.format(date);
		}
	}
}